package servlet.car;

import util.DbUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/DeleteCarServlrt")
public class DeleteCarServlrt extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int id = Integer.parseInt(request.getParameter("id"));
        DbUtil dbUtil = new DbUtil();
        String sql = "delete from car where id = " + id;
        System.out.println(sql);
        if (dbUtil.executeUpdate(sql) > 0) {
            response.setContentType("text/html;charset=utf-8");
            response.getWriter().print("<script language='javascript'>alert('删除成功！！');</script>");
            response.sendRedirect("GotoCarServlet");
        }
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
